<?php

namespace App\Admin\Controllers;

use App\Models\Transfer;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class TransferController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Transfer::with(['from', 'to']), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('from_user');
            $grid->column('from.email', '转出方邮箱');
            $grid->column('from.mobile', '转出方手机号');
            $grid->column('to_user');
            $grid->column('to.email', '接收方邮箱');
            $grid->column('to.mobile', '接收方手机号');
            $grid->column('coin');
            $grid->column('number');
            $grid->column('fee');
            $grid->column('get_number');
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('from_user');
                $filter->equal('from.email', '转出方邮箱');
                $filter->equal('from.mobile', '转出方手机号');
                $filter->equal('to_user');
                $filter->equal('to.email', '接收方邮箱');
                $filter->equal('to.mobile', '接收方手机号');
            });
            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
